package libnetdb.dm.assoc.util;
import java.util.Iterator;

/**
 * This class provides a easy transformation for those objects
 * which can find the next element easily to an
 * <code>Iterator</code>.
 *
 * @author Cheng-Ru Lin
 * @version 1.0
 */

public abstract class IteratorAdapter implements Iterator {
    protected Object value = null;

    /**
     * Gets the next elment of this iterator. Any subclass only need to
     * implemnet this function, then it can be used as an iterator. Note that
     * return <code>null</code> means no elements are avaliable.
     *
     * @return the next element of this iterator or null if no such element
     */
    abstract protected Object findNext();

    public boolean hasNext(){
        return value != null;
    }

    public Object next() {
        Object obj = value;
        value = findNext();
        return obj;
    }

    public void remove() {
        throw new UnsupportedOperationException("Method remove() not yet implemented.");
    }
}